package control;
import java.util.ArrayList;

import model.*;
import db.*;

public class InvoiceCtrl
{
	DBInvoice dbInv = new DBInvoice();
	
	public InvoiceCtrl()
	{
		
	}
	
	public ArrayList<Invoice> getAllInvoice()
	{
		ArrayList<Invoice> allInv = new ArrayList<Invoice>();
		allInv = dbInv.getAllInvoices(false);
		return allInv;
	}
	
	public Invoice getInvoiceInvoiceId(String id)
	{
		return dbInv.getInvoiceInvoiceId(id, true);
	}
	
	public Invoice getInvoiceCustomerId(String customerId)
	{
		return dbInv.getInvoiceCustomerId(customerId, true);
	}
	
	public void insertInvoice(int invoiceNo, String paymentDate, double amount, int customerId) throws Exception
	{
		Invoice toInsert = new Invoice();
		toInsert.setInvoiceNo(invoiceNo);
		toInsert.setPaymentDate(paymentDate);
		toInsert.setAmount(amount);
		toInsert.setCustomerId(customerId);
		dbInv.insertInvoice(toInsert);
	}
	
	public int updateInvoice(int invoiceNo, String paymentDate, double amount, int customerId)
	{
		Invoice inv = new Invoice();
		inv.setInvoiceNo(invoiceNo);
		inv.setPaymentDate(paymentDate);
		inv.setAmount(amount);
		inv.setCustomerId(customerId);
		return dbInv.updateInvoice(inv);
	}
	
	public void deleteInvoice(String id)
	{
		dbInv.deleteInvoice(id);
	}
}
